package  
{
	import flash.events.EventDispatcher;
	import flash.net.URLLoader
	import flash.net.URLRequest
	import flash.events.Event
	import flash.events.HTTPStatusEvent
	import flash.events.IOErrorEvent
	import flash.events.SecurityErrorEvent
	
	/**
	 * Lad xml file
	 * @author Artem.Kolesnikov
	 */
	public class XMLLoader extends EventDispatcher
	{
		// class vars
		public var data:Object; // here stored data
		private var _loader:URLLoader;
		
		public function XMLLoader() 
		{
			// empty constructor
		}
		
		public function load(url:String):void
		{
			_loader = new URLLoader(new URLRequest(url));
			_loader.addEventListener( Event.COMPLETE, _handleComplete );
			_loader.addEventListener( IOErrorEvent.IO_ERROR, _handleError );
		}
			
		private function _handleComplete(event:Event):void
		{
			var xml:XML;
			xml = new XML(_loader.data);
			data = xml;
			dispatchEvent(new Event(Event.COMPLETE));
		}
		
		private function _handleError(event:IOErrorEvent):void
		{
			dispatchEvent(new Event(Event.CANCEL));
		}
		
		public function destroy():void
		{
			_loader.removeEventListener( Event.COMPLETE, _handleComplete );
			_loader.removeEventListener( IOErrorEvent.IO_ERROR, _handleError );
			_loader = null;
		}
	}

}